class Course(object):
    courses = []
    def __init__(self, name, id, teacher, student_list, course_nature, course_capacity):
        self.name = name
        self.id = id
        self.teacher = teacher
        self.student_list = student_list
        self.course_nature = course_nature
        self.course_capacity = course_capacity
        self.course_chosen = len(self.student_list)
        self.course_remain = self.course_capacity - len(self.student_list)
        Course.courses.append(self.name)


    def show_info(self):
        print("*" * 15 + "信息如下：" + "*" * 15)
        print("课程名：%s" % self.name)
        print("课程号：%d" % self.id)
        print("老师：%s" % self.teacher.name)
        print("学生列表：")
        for stu in self.student_list:
            print(stu.name)
        print("课程性质：%s" % self.course_nature)
        print("课程容量：%d" % self.course_capacity)
        print("已选人数：%d" % self.course_chosen)
        print("剩余人数：%d" % self.course_remain)


    def course_selection(self, student):
        if student in self.student_list:
            raise Exception('学生已选择该门课！')
        if self.course_remain == 0:
            raise Exception('课程已满！')
        self.student_list.append(student)
        self.course_chosen += 1
        self.course_remain -= 1
        # 把课程和学生建立联系
        student.add_course(self)
        return True


    def course_withdrawal(self, student):
        if student in self.student_list:
            self.student_list.remove(student)
            self.course_chosen -= 1
            self.course_remain += 1
            return True
        else:
            raise Exception('该学生未选择该门课！')


    @classmethod
    def show_all_courses(cls):
        print(cls.courses)